package web;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.xml.sax.InputSource;

import web.opodoElements.AirSearchResponse;

public class UnmarshallerOpodo {

	public AirSearchResponse fromXmlToClasses(String xml) throws JAXBException, IOException{
		InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
        InputSource inputSource = new InputSource(new InputStreamReader(inputStream));
        JAXBContext jaxbContext = JAXBContext.newInstance(web.opodoElements.AirSearchResponse.class);
        //conversione da xml a java object
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        AirSearchResponse mesObj = (AirSearchResponse)unmarshaller.unmarshal(inputSource);
        //convert the jaxb objects to collection models
        inputStream.close();
        return mesObj;
	}

}
